<template>
  <div class="org">
    <div class="left">
      <el-form
        v-loading="orgLoading"
        class="tree"
        element-loading-text="拼命加载中..."
      >
        <el-input
          v-model="filterText"
          placeholder="输入关键字进行过滤"
          clearable
          @keyup.enter.native="handleEnterKeyup"
        />
        <el-button
          type="primary"
          style="margin-left: 5px"
          :loading="loading"
          @click="handleSearch"
        >查询</el-button
        >
        <el-tree
          ref="tree"
          class="filter-tree"
          :data="data"
          :props="defaultProps"
          :filter-node-method="filterNode"
          accordion
          node-key="orgUnitID"
          show-checkbox
          :default-expanded-keys="expandTree"
          :default-checked-keys="defaultCheckedKeys"
          @check="handleCheckChange"
          @node-click="handleNodeClick"
        />
      </el-form>
    </div>
    <div class="right">
      <el-table
        :data="tableData"
        style="width: 100%"
        :header-cell-style="headerStyle"
        height="420"
      >
        <el-table-column
          align="center"
          prop="empId"
          label="员工号"
          width="80"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="personName"
          label="姓名"
          width="90"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="rank"
          label="圈数"
          width="160"
        >
          <!-- <template slot-scope="scope">
            <el-select
              v-model="scope.row.rank"
              @change="handleRankChange(scope.row)"
              @focus="handleFocus(scope.row.rank)"
            >
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </template> -->
        </el-table-column>
        <el-table-column align="center" label="操作">
          <template slot-scope="scope">
            <el-button
              type="danger"
              size="small"
              @click="handleConfirmDelete(scope.row)"
              style="margin-right: 5px"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
// import { getOrgData } from '@/api/org'
import { organizationData } from '../../../mock/controller/data/orgData'
export default {
  data () {
    return {
      orgLoading: false,
      loading: false,
      filterText: '',
      data: [],
      defaultProps: {
        children: 'children',
        label: 'orgUnitName'
      },
      expandTree: [],
      defaultCheckedKeys: [],
      tableData: []
    }
  },
  mounted () {
    this.data = organizationData.objRes
  },
  methods: {
    handleEnterKeyup () {},
    handleSearch () {},
    // 节点筛选
    filterNode (value, data) {
      if (!value) return true
      const param = data.orgUnitName || ''
      return param.indexOf(value) !== -1
    },
    handleCheckChange (data, checked) {
      console.log('data', data)
      console.log('checked', checked)
      console.log('getCheckedNodes', this.$refs.tree.getCheckedNodes())
    },
    // 点击单位获取单位id
    handleNodeClick (org) {},
    headerStyle () {},
    handleConfirmDelete () {}

    // getOrgData () {
    //   getOrgData().then(res => {
    //     console.log('res', res)
    //   })
    // }
  }
}
</script>

<style lang="less" scoped>
.org{display: flex;}
.left {
  width: 50%;
  .el-input{
      width: 80%;
  }
}
.right {
  width: 50%;
}
</style>
